home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / Solitaire / Sources / Klondike / DiscardPileDelegate.m < prev    next >
Text File  |  1994-01-12  |  2KB  |  119 lines

  1. /* indent:4  tabsize:8  font:fixed-width */
  2.  
  3. #import "DiscardPileDelegate.h"
  4. #import "SuitPileDelegate.h"
  5. #import "../Solitaire/Solitaire.h"
  6. #import "Klondike.h"
  7.  
  8. @implementation DiscardPileDelegate
  9.  
  10. - setDrawCardCount:(int)theCount
  11. {
  12.     maxIndex = theCount;
  13.     return self;
  14. }
  15.  
  16. - setSuitCardPileViews:(id [])theViews
  17. {
  18.     int i;
  19.     
  20.     for (i=0; i<4; i++)
  21.         suitCardPileViews[i] = *(theViews + i);
  22.  
  23.     return self;
  24. }
  25.  
  26.  
  27. - doubleClickedCard:aCard in:aCardPileView
  28. {
  29.     int i;
  30.     id tempCard;
  31.     
  32.     id    cardPile = [aCardPileView cardPile];
  33.     
  34.     if ((aCard == [cardPile cardAt:CS_TOP] ) && (![aCard isFaceUp]))
  35.     {
  36.     [aCard flip];
  37.     [aCardPileView display];
  38.     }
  39.     else if (aCard == [cardPile cardAt:CS_TOP])
  40.     {
  41.     for (i=0;i<4;i++)
  42.     {
  43.         [[suitCardPileViews[i] delegate] setDoubleClickCheck];
  44.         if ([[suitCardPileViews[i] delegate] canAcceptPile:cardPile
  45.                                           from:aCardPileView
  46.                                             in:suitCardPileViews[i]])
  47.         {
  48.         [[suitCardPileViews[i] cardPile] addCard:[cardPile
  49.                                                    cardAt:CS_TOP]];
  50.         [cardPile removeCard:[cardPile cardAt:CS_TOP]];
  51.         if (tempCard = [recycleCardPile cardAt:CS_TOP])
  52.         {
  53.             [recycleCardPile removeCard:tempCard];
  54.             [cardPile insertCard:tempCard at:CS_BOTTOM];
  55.         }
  56.         [aCardPileView display];
  57.         [suitCardPileViews[i] display];
  58.         [SolGameController() checkForWin];
  59.         break;
  60.         }
  61.     }
  62.     }
  63.     return self;
  64. }
  65.  
  66.  
  67. - (BOOL)draggedPile:aCardPile from:discardCardPileView
  68. {
  69.     id discardCardPile = [discardCardPileView cardPile];
  70.  
  71.     if (([aCardPile cardAt:CS_TOP]) == ([discardCardPile cardAt:CS_TOP]))
  72.     {
  73.     return YES;
  74.     }
  75.     return NO;
  76. }
  77.  
  78.  
  79. - removedPile:aCardPile from:discardCardPileView
  80. {
  81.     id discardCardPile = [discardCardPileView cardPile];
  82.     id aCard;
  83.  
  84.     if (maxIndex == 1) return self;
  85.     
  86.     if ([recycleCardPile cardCount] != 0)
  87.     {
  88.         aCard = [recycleCardPile cardAt:CS_TOP];
  89.     [recycleCardPile removeCard:aCard];
  90.     [discardCardPile insertCard:aCard at:CS_BOTTOM];
  91.     [discardCardPileView display];
  92.     }
  93.  
  94.     return self;
  95. }
  96.  
  97.  
  98. - getOffset:(float *) xOffset :(float *) yOffset forSize:(CardSize)aSize
  99. {
  100.     if (aSize == CS_SMALL)
  101.     {
  102.         if (maxIndex == 1)
  103.         *xOffset = 0.5;
  104.     else
  105.         *xOffset = 15.0;
  106.     }
  107.     else
  108.     {
  109.         if (maxIndex == 1)
  110.         *xOffset = 0.5;
  111.     else
  112.         *xOffset = 20.0;
  113.     }    
  114.     *yOffset = 0.0;
  115.     return self;
  116. }
  117.  
  118. @end
  119.